//
//  ZXStatusOriginalFrm.m
//  ZXOCWeiBo
//
//  Created by mac on 15/12/10.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZXStatusOriginalFrm.h"
#import "ZXStatusPhotosVIew.h"

@implementation ZXStatusOriginalFrm

-(void)setStatuses:(ZXStatuses *)statuses
{
    _statuses = statuses;
    
    //计算各个子控件的frm
    
    //头像
    CGFloat avatarX = ZXStatusCellInset;
    CGFloat avatarY = ZXStatusCellInset;
    CGFloat avatarW = 35;
    CGFloat avatarH = avatarW;
    self.avatarFrm = CGRectMake(avatarX, avatarY, avatarW, avatarH);
    
    //昵称
    CGFloat nameX = CGRectGetMaxX(self.avatarFrm) + ZXStatusCellInset;
    CGFloat nameY = ZXStatusCellInset;
//    计算“昵称” 所占用的尺寸 - 文字大小决定
    NSDictionary * textAtt = @{NSFontAttributeName : ZXStatusOrginlNameFont};
 CGSize nameSize = [statuses.user.screen_name sizeWithAttributes:textAtt];
    self.nameFrm = (CGRect){nameX,nameY,nameSize};
    
//    会员
    CGFloat vipX = CGRectGetMaxX(self.nameFrm) + ZXStatusCellInset;
    CGFloat vipY = ZXStatusCellInset;
    CGFloat vipW = nameSize.height;
    CGFloat vipH = vipW;
    self.vipFrm = CGRectMake(vipX, vipY, vipW, vipH);
    
//    时间
    CGFloat timeX = nameX;
    CGFloat timeY = CGRectGetMaxY(self.nameFrm) + ZXStatusCellInset;
    textAtt = @{NSFontAttributeName : ZXStatusOrginlTimeFont};
    CGSize timeSize = [statuses.created_at sizeWithAttributes:textAtt];
    self.timeFrm = (CGRect){timeX,timeY,timeSize};
    
//    来源
    CGFloat sourceX = CGRectGetMaxX(self.timeFrm) + ZXStatusCellInset;
    CGFloat sourceY = timeY;
    textAtt = @{NSFontAttributeName : ZXStatusOrginlSoureFont};
    CGSize sourceSize = [statuses.source sizeWithAttributes:textAtt];
    self.sourceFrm = (CGRect){sourceX,sourceY,sourceSize};
    
//    正文
    CGFloat textX = ZXStatusCellInset;
    CGFloat textY = CGRectGetMaxY(self.avatarFrm) + ZXStatusCellInset;
    
    textAtt = @{NSFontAttributeName : ZXStatusOrginlTextFont};
    CGSize maxSize = CGSizeMake(UIScreenW - ZXStatusCellInset * 2, MAXFLOAT);
 CGSize textSize = [statuses.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:textAtt context:nil].size;
    
    self.textFrm = (CGRect){textX,textY,textSize};
    
//    photosFrm
    CGFloat photosX = textX;
    CGFloat photosY = CGRectGetMaxY(self.textFrm);
    CGSize  photosSize = [ZXStatusPhotosVIew photosSizeWithPicCount:statuses.pic_urls.count];
    self.photosFrm = (CGRect){photosX,photosY,photosSize};
    
    //自身的frm
    if (statuses.pic_urls.count > 0)
    {
     //有照片的情况
        self.selfFrm = CGRectMake(0, 0, UIScreenW, CGRectGetMaxY(self.photosFrm) + ZXStatusCellInset);
    }
    else
    {
        //没有照片
        self.selfFrm = CGRectMake(0, 0, UIScreenW, CGRectGetMaxY(self.textFrm) + ZXStatusCellInset);
    }
  
    
}

@end
